﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<!-- 富文本编辑器 -->
<link rel="stylesheet" type="text/css"
	href="${path }/resource/plugin/kindeditor/themes/default/default.css" />
<link rel="stylesheet" type="text/css"
	href="${path }/resource/plugin/kindeditor/plugins/code/prettify.css" />
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/kindeditor.js"></script>
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript"
	src="${path }/resource/plugin/kindeditor/plugins/code/prettify.js"></script>
	

<title></title>
</head>
<div class="ibox-content">
	<form class="form-horizontal" id="dataform"
		onsubmit="javascripr:return false;">
		<input type="hidden" name="tokenUrl" value="${tokenUrl}">	 
		<input type="hidden" name="token" value="${token}">
		<c:if test="${obj ne null and !copy }">
			<input type="hidden" name="id" value="${obj.id }">
		</c:if>
		
		
		
		<div class="form-group">
			<label class="col-sm-2 control-label">任务类型</label>
			<div class="col-sm-8">
				<select name="taskType" class="form-control autoFull" id="taskType"
					onchange="changeIsShow()"
					data-url="${path}/admin/task/showALLTaskType"
					data-def="${obj.taskType }"
					data-filed="name" data-value="name"
					dataType="*" nullmsg="任务类型不能为空">
					<option value="">--请选择任务类型--</option>
				</select>				
			</div>
			<div class="Validform_checktip"></div>
		</div>			
		
		<div id="isshow"
			<c:if test="${obj eq null || obj.taskType ne '开发任务' }">style="display: none;"</c:if>
			 >		
			<div class="form-group">
				<label class="col-sm-2 control-label">关联项目</label>
				<div class="col-sm-8">
					<select name="projId" class="form-control autoFull select2" id="projId"
						onchange="selectProj()"
						data-url="${path}/admin/task/queryAllProject"
						data-def="${obj.projId }"
						data-filed="projName" data-value="id"
						dataType="*" nullmsg="关联项目不能为空" ignore="ignore">
						<option value="">--请选择关联项目--</option>
					</select>				
				</div>
				<div class="Validform_checktip"></div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">项目模块</label>
				<div class="col-sm-8">
					<select class="form-control select2" size="1" name="cateId"  onchange="changeTitle()"
						id="parentId" >
						<option value="-10" selected="selected">请选择项目模块</option>
					</select>				
				</div>
			</div>			
		
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">任务名称</label>
			<div class="col-sm-8">
				<input type="text" id="taskName" name="name" value="<c:out value="${obj.name }"></c:out>"
					class="form-control radius" dataType="*1-500">
				<div class="Validform_checktip"></div>
			</div>
		</div>									
		
		<div class="form-group">
			<label class="col-sm-2 control-label">任务等级</label>
			<div class="col-sm-8">
				<select name="level" class="form-control autoFull" id="level"
					data-url="${path}/admin/task/showALLTaskLevel"
					data-def="${obj.level }"
					data-filed="name" data-value="name"
					dataType="*" nullmsg="任务等级不能为空">
				</select>				
			</div>
			<div class="Validform_checktip"></div>
		</div>
		
		
		
		<div class="form-group">
			<label class="col-sm-2 control-label">预计结束时间</label>
			<div class="col-sm-8">
				<input type="text" dataType="*" class="form-control datetimepicker"
					value="<fmt:formatDate value="${obj.endTime }" pattern='yyyy-MM-dd' />"
					name="endTime" nullmsg="预计结束时间不能为空">				
			</div>
			<div class="Validform_checktip"></div>
		</div>
		
		<div class="form-group">
		    <label class="col-sm-2 control-label">故事点数</label>
		    <div class="col-sm-8">
		    
		       <select class="form-control" name="experienceNum" 
		        dataType="n" errormsg="填写正整数" ignore="ignore">
		        <option value="1"  <c:if test="${obj.experienceNum eq 1}">selected="selected"</c:if>>1</option>
		        <option value="2" <c:if test="${obj.experienceNum eq 2}">selected="selected"</c:if>>2</option>
		        <option value="3" <c:if test="${obj.experienceNum eq 3}">selected="selected"</c:if>>3</option>
		        <option value="4" <c:if test="${obj.experienceNum eq 4}">selected</c:if>>4</option>
		        <option value="5" <c:if test="${obj.experienceNum eq 5}">selected</c:if>>5</option>
		      </select>
		    </div>
		</div>
		<%-- <div class="form-group">
		    <label class="col-sm-2 control-label">金币值</label>
		    <div class="col-sm-8">
		     <input class="form-control" name="goldNum" 
		     dataType="n1-6" errormsg="填写正整数,长度不要超过6位" ignore="ignore" value="${obj.goldNum}">
		    </div>
		</div> --%>
		
		<div class="form-group">
			<label class="col-sm-2 control-label"></label>			
			<div class="col-sm-8">
				<input type="button" class="btn btn-w-m btn-warning" value="全选" onclick="checkAll()">
				<input type="button" class="btn btn-w-m btn-info" value="全不选" onclick="checkNoAll()" >
				<input type="button" class="btn btn-w-m btn-primary" value="反选" onclick="reverseCheck()">
			</div>		
		</div>
		
		<div class="form-group">
			<label class="col-sm-2 control-label">指派人</label>
			<input type="hidden" name="strUserId" id="strUserId" value="${obj.userId }">
			<div class="col-sm-8" id="assignPerson">
					
			</div>
			<div class="Validform_checktip"></div>			
		</div>
		
		
		<div class="form-group">
			<label class="col-sm-2 control-label">任务描述</label>
			<div class="col-sm-8">
				<textarea name="describes" id="describes" >${obj.describes}
				</textarea>
			</div>
			<div class="Validform_checktip"></div>
		</div>		
		
		<div class="form-group ">
			<div class="col-sm-12 text-center">
				<a href="javascript:;" onclick="myForm.submit()"
					class="btn btn-success radius">保存</a>&nbsp;&nbsp;&nbsp;&nbsp; 
					<button onclick="MTools.closeForm()" class="btn btn-danger radius" type="button">取消</button>
			</div>
		</div>
	</form>
	
	
</div>
	
<script type="text/javascript">
	function changeTitle(){
		var selectName=$("#parentId option:selected").text().replace("-","").replace("|","").trim();
		var name=$("#taskName").val();
		$("#taskName").val(selectName+" - "+name);
	}
 	var editor = null;
 	var myForm;
	$(function() {	
		//初始化页面的一些元素以及数据
		MTools.autoFullSelect();
		MTools.ininDatetimepicker({
			maxView : 3,
			minView : 2,
			state : "aferToday",
			listenBlur : true,
		});	
		//带搜索的下拉框
		$(".select2").select2({'width':'100%'});
		$(".select2").trigger("blur");
		//创建富文本
		MUI.createEdit("describes", '100%', '400px', 'editor');
		//默认初始化指派人复选框
		initEmployee();
		
		//表格初始化
		myForm=MForm.initForm({
			invokeUrl:"${path}/admin/task/addOrModify",
			beforeSubmit:function(){
				//同步富文本内容
				editor.sync();				
				var taskType = $("#taskType").val();
				console.log("taskType"+taskType);
				//修改任务的时候，将开发任务转为其他任务，将项目和模块清空
				/* <c:if test="${obj ne null && obj.taskType ne null }"> 
					taskType = "${obj.taskType}";				
				</c:if> */
				console.log("taskType"+taskType);
				if(taskType!="" && taskType != "开发任务"){
					console.log("清空了");
					$("#projId").html("");
					$("#parentId").html("");					
				}	
				//获取富文本内容
				/* var describes = $("#describes").val();
				console.log(describes);
				alert(describes); */	
			},
			afterSubmit:function(loj){
				var tempUser=loj.attr("result").mapInfo.tempUser;
				
				if(tempUser!=null && tempUser !=""){
					if(tempUser.jobTitle!=null&&tempUser.jobTitle>=0 ){
						$(parent.parent.jobTitle).html("故事点数"+tempUser.jobTitle);
					}
					if(tempUser.age!=null&&tempUser.age>=0){
						$(parent.parent.age).html("金币"+tempUser.age);
					}
					if(tempUser.grade!=null&&tempUser.grade>=0){
						$(parent.parent.grade).html("故事点数"+tempUser.grade);
					} 
				}				
				parent.myGrid1.serchData();
				parent.myGrid2.serchData();				
			},
		});
		//当obj不为空是，去初始化模块
		<c:if test="${obj ne null && obj.projId ne null }"> 
			var projId2 = ${obj.projId};
			if(projId2 != ""){
				initFunctionList(projId2);
				initProjUser(projId2);
			}			
		</c:if>

	});
	
	//控制项目和模块是否显示
	function changeIsShow(){
		var taskType= $("#taskType").val();
		if(taskType == "开发任务"){
			$("#isshow").show();
			$("#projId").removeAttr("ignore");			
		}else{
			$("#isshow").hide();			
			$("#projId").attr("ignore","ignore");
			initEmployee();
		}
	}
	
	//检查富文本框是否填写了值，有就去掉dataType属性（暂未用）
	function checkIsNull(){
		var describes = $("#describes").val();
		console.log(describes);
		if(describes == ""){
			$("#describes").removeAttr("dataType");
		}else{
			$("#describes").attr("dataType","*");
		}
	}
	
	//项目改变触发事件
	function selectProj(){
		var projId = $("#projId").val();
		//初始化模块
		initFunctionList(projId);
		//当项目改变的时候，修改指派人
		if(projId != ""){
			/* $("#userId").removeData("url");
			$("#userId").data("url","${path}/admin/task/queryAllProjUser?projId="+projId);
			$("#userId").data("filed","userName");
			$("#userId").empty();
			$("#userId").append('<option value="">-- 请选择指派人--</option>');
			MTools.autoFullSelect({selecteder:".autoFull2"});
			$(".select2").select2({'width':'100%'}); */
			initProjUser(projId)		
		} 
		
	}
	
	//初始化项目模块
	function initFunctionList(projId) {
		$.AjaxProxy({
			a : false,
			c : false
		}).invoke(
			"${path}/admin/interfaceCate/all?projId="+projId,
			function(loj) {
				$("#parentId").createSelectTree(
					loj.attr("result").rows, {
					append : false ,
					defaultValue: "${obj.cateId}"
					});
				});	
	}

	//加载所有的员工，为指派人
	function initEmployee(){
		var html = '';
		$.AjaxProxy({
			a : false,
			c : false
			}).invoke(
				"${path}/admin/task/queryAllUser",
				function(loj){
			for(var i = 0; i < loj.getRowCount(); i++){				
				html += "<input type='checkbox' name='assignPerson' value='"
					+loj.getString(i,"id")+"' onchange='getUserId()'";
				<c:if test="${obj ne null && obj.userId ne null }"> 
					var id = loj.getString(i,"id");
					var userId = ${obj.userId};
					if(id == userId){
						html += "checked='checked'"
					}			
				</c:if>
				html +=">&nbsp;"
					+loj.getString(i,"name")+"&nbsp;&nbsp;&nbsp;&nbsp;"; 
			}
		})
		$("#assignPerson").empty().html(html);
	}
	
	//加载所有的员工，为指派人
	function initProjUser(projId){
		var html = "";
		$.AjaxProxy({
			a : false,
			c : false
			}).invoke(
				"${path}/admin/task/queryAllProjUser?projId="+projId,
				function(loj){
			for(var i = 0; i < loj.getRowCount(); i++){
				html += "<input type='checkbox' name='assignPerson' value='"
					+loj.getString(i,"userId")+"' onchange='getUserId()'";
				<c:if test="${obj ne null && obj.userId ne null }"> 
					var id = loj.getString(i,"userId");
					var userId = ${obj.userId};
					if(id == userId){
						html += "checked='checked'"
					}			
				</c:if>
				html += "dataType='*' nullmsg='请选择指派人'"
					+">&nbsp;"
					+loj.getString(i,"userName")+"&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			html += '<div class="Validform_checktip"></div>';
		})
		$("#assignPerson").empty().html(html);
	}
	
	
	//拼接指派人id
	function getUserId(){
		var checkbox = document.getElementsByName("assignPerson");
		var receiveId="";
		for(var i=0;i<checkbox.length;i++){
			if(checkbox[i].checked){
				receiveId+=checkbox[i].value+",";
			}
		}
		$("#strUserId").val(receiveId);
	}
	
	//全选或全部选
	function checkAll(){
		$("[name=assignPerson]:checkbox").each(function(){
			$(this).prop("checked",true);
		});
	}
	
	//全不选
	function checkNoAll(){
		$("[name=assignPerson]:checkbox").each(function(){
			$(this).prop("checked",false);
		});
	}
	
	//反选
	function reverseCheck(){
		$("[name=assignPerson]:checkbox").each(function(){
			this.checked=!this.checked;
		});
	}
	
	
   
</script>
</body>
</html>